﻿@{
    ViewData["Title"] = "用户信息";
    ViewData["Mbx"] = "系统管理";
    Layout = "_Default";
}

@section gray{
<span class="l">
        <a class="btn btn-primary radius" href="javascript:;" onclick="common_add('添加用户','/admin/useradd','800','500')">
        <i class="Hui-iconfont">&#xe600;</i> 新增
    </a>
</span>
}

<table class="table table-border table-bordered table-hover table-bg table-sort">
    <thead>
    </thead>
    <tbody>
    </tbody>
</table>

@section javascript{
<script>
    $(function(){
        $('.table-sort').dataTable({
            bProcessing: true, //DataTables 载入数据时，是否显示‘进度’提示
            bAutoWidth: false, //自动宽度
            bSort: false, //排序功能
            paging : true, //是否分页
            bInfo: true, //页脚信息,默认为 true
            bStateSave: false, //状态保存
            sPaginationType: "full_numbers", //分页显示样式
            //serverSide: true, //启用服务器分页
            searching: true, //关闭 datatables 的搜索框
            destroy: true, //解决重新渲染问题
            iDisplayLength: 10, //每页显示数量
            ajax:{
                    url: "/admin/userlist",
                    type: "POST",
                    contentType: "application/x-www-form-urlencoded",
                    async: false,
                    dataType: "json",
                    data: function(data){

                    },
                    dataFilter: function(json){
                        return json;
                    }
               },
            aoColumns:[
                {mDataProp:"userName", sClass:"text-c",  sTitle:"用户名",sDefaultContent:"",sWidth:"10%"},
                {mDataProp:"fullName", sClass:"text-c", sTitle:"姓名",sDefaultContent:"",sWidth:"20%"},
                {mDataProp:"department", sClass:"text-c", sTitle:"部门",sDefaultContent:"",sWidth:"15%"},
                {mDataProp:"jobNumber", sClass:"text-c", sTitle:"工号",sDefaultContent:"",sWidth:"10%"},
                {mDataProp:"roleFullName", sClass:"text-c", sTitle:"角色名称",sDefaultContent:"",sWidth:"15%"},
                {mDataProp:"updateTime",  sClass:"text-c", sTitle:"更新时间",sWidth:"15%",
                  mRender:function(data, type, row){
                      var time= transformTimestamp(data);
                      return time;
                  }
                },
                {mDataProp:"js_Id", sClass:"text-c", sTitle:"操作",sWidth:"15%",
                 mRender: function(data, type, row){
                            var html = "<a title=\"编辑\" href=\"javascript:;\" onclick=\"common_add('编辑用户',\'/admin/useradd/" + data + "','800','500')\" class=\"ml-5\" style=\"text-decoration:none\"><i class=\"Hui-iconfont\">&#xe6df;</i></a>";
                       html+= "<a title=\"重置密码\" href=\"javascript:;\" onclick=\"resetUserPwd('"+data+"','"+row.userName+"')\" class=\"ml-5\" style=\"text-decoration:none\"><i class=\"Hui-iconfont\">&#xe6f7;</i></a>";
                       html+= "<a title=\"删除\" href=\"javascript:;\" onclick=\"delUser('"+data+"','"+row.userName+"')\" class=\"ml-5\" style=\"text-decoration:none\"><i class=\"Hui-iconfont\">&#xe6e2;</i></a>";
                          return html;
                    }
                 }
            ],
            oLanguage: { //国际化配置
                sProcessing : "正在获取数据，请稍后...",
                sLengthMenu : "显示 _MENU_ 条",
                sZeroRecords : "没有您要搜索的内容",
                sInfo : "从 _START_ 到  _END_ 条记录 总记录数为 _TOTAL_ 条",
                sInfoEmpty : "记录数为0",
                sInfoFiltered : "(全部记录数 _MAX_ 条)",
                sInfoPostFix : "",
                sSearch : "从当前数据中检索： ",
                sUrl : "",
                oPaginate: {
                    sFirst : "首页",
                    sPrevious : "上一页",
                    sNext : "下一页",
                    sLast : "尾页"
                }
            }
        });
    });
     function resetUserPwd(id,s){
        popupConfirm("确定重置'"+s+"'用户密码嘛？",0,function(){
                var data={ 'id':id, 'status':s };
                SubmitFormForAjax("/admin/resetuserpwd", data, function (data) {
                 if (data.result) {
                     popupAlert('重置成功！',1,function(){
                          location.reload();//刷新页面
                     });
                 }else{
                      popupAlert(data.message,1,function(data){layer.close(data);});
                 }
             },true);

        })
     }
         function delUser(id,s){
        popupConfirm("确定删除'"+s+"'用户嘛？",0,function(){
                var data={ 'id':id, 'status':s };
                SubmitFormForAjax("/admin/deluser", data, function (data) {
                 if (data.result) {
                     popupAlert('删除成功！',1,function(){
                          location.reload();//刷新页面
                     });
                 }else{
                      popupAlert(data.message,1,function(data){layer.close(data);});
                 }
             },true);

        })
     }

</script>
}
